/* eslint-disable */
import React, { Component } from 'react'
import store from '../../redux/store'
import {
	createJiaAction,
	createJianAction,
	createJiaOddAction,
	createJiaWaitAction,
	createJiaServerAction
} from '../../redux/actions/count'

export default class Count extends Component {
	state = {school:'尚硅谷'} //初始化状态
	render() {
		console.log('Count---render')
		const {he,rens} = store.getState()
		return (
			<div>
				<h3>我是Count组件</h3>
				<h4>当前求和为：{he}</h4>
				<h4>下方Person组件总人数为：{rens.length}</h4>
				<select ref={c => this.selectNumber = c}>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
				</select> &nbsp;
				<button onClick={this.increment}>+</button>&nbsp;
				<button onClick={this.decrement}>-</button>&nbsp;
				<button onClick={this.incrementOdd}>奇数再+</button>&nbsp;
				<button onClick={this.incrementWait}>等一等再+</button>&nbsp;
				<button onClick={this.incrementServer}>等着服务器返回数据再+</button>
			</div>
		)
	}
	//加法
	increment = ()=>{
		const {value} = this.selectNumber
		store.dispatch(createJiaAction(value*1))
		// store.dispatch({type:'wstyrydtrtydyudtyu',data:value*1})
	}
	//减法
	decrement = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		//分发一个action
		store.dispatch(createJianAction(value*1))
	}
	//加法（奇数）
	incrementOdd = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		//分发一个action
		store.dispatch(createJiaOddAction(value*1))
	}
	//加法（等一等）
	incrementWait = ()=>{
		//获取用户的输入
		const {value} = this.selectNumber
		//分发一个action
		store.dispatch(createJiaWaitAction(value*1,500))
	}
	incrementServer = ()=>{
		store.dispatch(createJiaServerAction())
	}

	componentDidMount(){
		store.subscribe(()=>{
			this.forceUpdate()
		})
	}
}
